<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="车间代号" prop="plant">
        <el-select v-model="queryParams.plant" placeholder="请选择车间">
          <el-option
            v-for="item in dict.type.bus_plant_rl"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="造型线" prop="lineNum">
        <el-input
          v-model="queryParams.lineNum"
          placeholder="请输入造型线"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计划号" prop="planNum">
        <el-input
          v-model="queryParams.planNum"
          placeholder="请输入计划号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="炉号" prop="furnaceNum">
        <el-input
          v-model="queryParams.furnaceNum"
          placeholder="请输入炉号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="质检类型" prop="zjlx">
        <el-input
          v-model="queryParams.zjlx"
          placeholder="请输入质检类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否合格" prop="qual">
        <el-select v-model="queryParams.qual" placeholder="请选择">
          <el-option
            v-for="item in dict.type.is_qual"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="文件名" prop="filename">
        <el-input
          v-model="queryParams.filename"
          placeholder="请输入文件名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="牌号" prop="markId">
        <el-input
          v-model="queryParams.markId"
          placeholder="请输入牌号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班别" prop="bClass">
        <el-input
          v-model="queryParams.bClass"
          placeholder="请输入班别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="质检人" prop="inspector">
        <el-input
          v-model="queryParams.inspector"
          placeholder="请输入质检人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入库时间" prop="storageTime">
        <el-date-picker clearable
          v-model="queryParams.storageTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择入库时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['bus:detectionRl:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['bus:detectionRl:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['bus:detectionRl:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['bus:detectionRl:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="detectionRlList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="业务主键ID" align="center" prop="id" />
      <el-table-column label="车间代号" align="center" prop="plant">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bus_plant_rl" :value="scope.row.plant"/>
        </template>
      </el-table-column>
      <el-table-column label="造型线" align="center" prop="lineNum" />
      <el-table-column label="计划号" align="center" prop="planNum" />
      <el-table-column label="炉号" align="center" prop="furnaceNum" />
      <el-table-column label="熔炼炉次号" align="center" prop="meltNum" />
      <el-table-column label="球化包次号" align="center" prop="packNum" />
      <el-table-column label="质检类型" align="center" prop="zjlx" />
      <el-table-column label="是否合格" align="center" prop="qual">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.is_qual" :value="scope.row.qual"/>
        </template>
      </el-table-column>
      <el-table-column label="文件名" align="center" prop="filename"  width="200px"  />
      <el-table-column label="质检记录信息" align="center" prop="allRecord" />
      <el-table-column label="录入炉号" align="center" prop="furnacePlant" />
      <el-table-column label="牌号规范" align="center" prop="mark" />
      <el-table-column label="牌号ID" align="center" prop="markId" />
      <el-table-column label="唯一名称" align="center" prop="only" />
      <el-table-column label="类型标样" align="center" prop="type" />
      <el-table-column label="CE值" align="center" prop="ceValue" />
      <el-table-column label="c" align="center" prop="c" />
      <el-table-column label="Si" align="center" prop="si" />
      <el-table-column label="Mn" align="center" prop="mn" />
      <el-table-column label="p" align="center" prop="p" />
      <el-table-column label="s" align="center" prop="s" />
      <el-table-column label="Cr" align="center" prop="cr" />
      <el-table-column label="mo" align="center" prop="mo" />
      <el-table-column label="ni" align="center" prop="ni" />
      <el-table-column label="ai" align="center" prop="ai" />
      <el-table-column label="co" align="center" prop="co" />
      <el-table-column label="cu" align="center" prop="cu" />
      <el-table-column label="nb" align="center" prop="nb" />
      <el-table-column label="ti" align="center" prop="ti" />
      <el-table-column label="sn" align="center" prop="sn" />
      <el-table-column label="班别" align="center" prop="bClass" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="质检人" align="center" prop="inspector" />
      <el-table-column label="入库时间" align="center" prop="storageTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.storageTime, '{y}-{m}-{d} {h}:{m}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['bus:detectionRl:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['bus:detectionRl:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改熔炼质检光谱结果对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="车间代号" prop="plant">
              <el-select v-model="form.plant" placeholder="请选择车间">
                <el-option
                  v-for="item in dict.type.bus_plant_rl"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="造型线" prop="lineNum">
              <el-input v-model="form.lineNum" placeholder="请输入造型线" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="计划号" prop="planNum">
          <el-input v-model="form.planNum" placeholder="请输入计划号" />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="炉号" prop="furnaceNum">
              <el-input v-model="form.furnaceNum" placeholder="请输入炉号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="熔炼炉次号" prop="meltNum">
              <el-input v-model="form.meltNum" placeholder="请输入熔炼炉次号" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="球化包次号" prop="packNum">
          <el-input v-model="form.packNum" placeholder="请输入球化包次号" />
        </el-form-item>

        <el-row>
          <el-col :span="12">
            <el-form-item label="质检类型" prop="zjlx">
              <el-input v-model="form.zjlx" placeholder="请输入质检类型" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否合格" prop="qual">
              <el-select v-model="form.qual" placeholder="请选择">
                <el-option
                  v-for="item in dict.type.is_qual"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="文件名" prop="filename">
          <el-input v-model="form.filename" placeholder="请输入文件名" />
        </el-form-item>
        <el-form-item label="质检记录信息" prop="allRecord">
          <el-input v-model="form.allRecord" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="录入炉号" prop="furnacePlant">
          <el-input v-model="form.furnacePlant" placeholder="请输入录入炉号" />
        </el-form-item>

        <el-row>
          <el-col :span="12">
            <el-form-item label="牌号规范" prop="mark">
              <el-input v-model="form.mark" placeholder="请输入牌号规范" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="牌号ID" prop="markId">
              <el-input v-model="form.markId" placeholder="请输入牌号ID" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="CE值" prop="ceValue">
              <el-input-number v-model="form.ceValue" placeholder="请输入CE值" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="c" prop="c">
              <el-input-number v-model="form.c" placeholder="请输入c" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="Si" prop="si">
              <el-input-number v-model="form.si" placeholder="请输入Si" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="Mn" prop="mn">
              <el-input-number v-model="form.mn" placeholder="请输入Mn" />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="12">
            <el-form-item label="p" prop="p">
              <el-input-number v-model="form.p" placeholder="请输入p" />
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="s" prop="s">
              <el-input-number v-model="form.s" placeholder="请输入s" />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="12">
            <el-form-item label="Cr" prop="cr">
              <el-input-number v-model="form.cr" placeholder="请输入Cr" />
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="mo" prop="mo">
              <el-input-number v-model="form.mo" placeholder="请输入mo" />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="12">
            <el-form-item label="ni" prop="ni">
              <el-input-number v-model="form.ni" placeholder="请输入ni" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="ai" prop="ai">
              <el-input-number v-model="form.ai" placeholder="请输入ai" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="co" prop="co">
              <el-input-number v-model="form.co" placeholder="请输入co" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="cu" prop="cu">
              <el-input-number v-model="form.cu" placeholder="请输入cu" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="ti" prop="ti">
              <el-input-number v-model="form.ti" placeholder="请输入ti" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="sn" prop="sn">
              <el-input-number v-model="form.sn" placeholder="请输入sn" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="班别" prop="bClass">
          <el-input v-model="form.bClass"  placeholder="请输入班别" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="质检人" prop="inspector">
          <el-input v-model="form.inspector" placeholder="请输入质检人" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDetectionRl, getDetectionRl, delDetectionRl, addDetectionRl, updateDetectionRl } from "@/api/bus/detectionRl";

export default {
  name: "DetectionRl",
  dicts:['bus_plant_rl','is_qual'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 熔炼质检光谱结果表格数据
      detectionRlList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        plant: null,
        lineNum: null,
        planNum: null,
        furnaceNum: null,
        meltNum: null,
        packNum: null,
        zjlx: null,
        qual: null,
        filename: null,
        allRecord: null,
        furnacePlant: null,
        mark: null,
        markId: null,
        only: null,
        type: null,
        ceValue: null,
        c: null,
        si: null,
        mn: null,
        p: null,
        s: null,
        cr: null,
        mo: null,
        ni: null,
        ai: null,
        co: null,
        cu: null,
        nb: null,
        ti: null,
        v: null,
        w: null,
        pb: null,
        sn: null,
        mg: null,
        as: null,
        zr: null,
        bi: null,
        ce: null,
        sb: null,
        se: null,
        te: null,
        b: null,
        zn: null,
        la: null,
        fe: null,
        re: null,
        matched: null,
        bClass: null,
        state: null,
        inspector: null,
        storageTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        plant: [
          { required: true, message: '请选择车间', trigger: 'blur' }
        ],
        furnaceNum: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        c: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        qual: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        si: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        mn: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        s: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        p: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        cr: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        ni: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        sn: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        cu: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        lineNum: [
          { required: true, message: '必填项', trigger: 'blur' },
          // { type: 'email', message: '请输入有效的邮箱地址', trigger: ['blur', 'change'] }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询熔炼质检光谱结果列表 */
    getList() {
      this.loading = true;
      listDetectionRl(this.queryParams).then(response => {
        this.detectionRlList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        plant: null,
        lineNum: null,
        planNum: null,
        furnaceNum: null,
        meltNum: null,
        packNum: null,
        zjlx: null,
        qual: null,
        filename: null,
        allRecord: null,
        furnacePlant: null,
        mark: null,
        markId: null,
        only: null,
        type: null,
        ceValue: null,
        c: null,
        si: null,
        mn: null,
        p: null,
        s: null,
        cr: null,
        mo: null,
        ni: null,
        ai: null,
        co: null,
        cu: null,
        nb: null,
        ti: null,
        v: null,
        w: null,
        pb: null,
        sn: null,
        mg: null,
        as: null,
        zr: null,
        bi: null,
        ce: null,
        sb: null,
        se: null,
        te: null,
        b: null,
        zn: null,
        la: null,
        fe: null,
        re: null,
        matched: null,
        bClass: null,
        remark: null,
        state: null,
        inspector: null,
        createTime: null,
        storageTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加熔炼质检光谱结果";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDetectionRl(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改熔炼质检光谱结果";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDetectionRl(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDetectionRl(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除熔炼质检光谱结果编号为"' + ids + '"的数据项？').then(function() {
        return delDetectionRl(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('bus/detectionRl/export', {
        ...this.queryParams
      }, `detectionRl_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
